import { HTMLElement } from 'node-html-parser';
import s from './ns';
import P01 from './P01';
import P02 from './P02';
import { IFeidaoAiNodejsComponent } from '@feidao/web/interfaces';
import nodejs from '@feidao/web/atom/nodejs/msg-b/nodejs';
import render from '@feidao/web/atom/nodejs/render/render';
import init from '@feidao/web/framework/nodejs/d/component';

const daoke = {
	async init(fd: IFeidaoAiNodejsComponent, ...args: any[]) {
		console.log('zj-reality-picture-001 init nb', args);
		const classroom_id = fd.data.params.classroom_id;
		console.log(classroom_id);
		const query = {
			criteria: { classroom_id },
			asc: ['fzno']
		};
		const res = await nodejs("flippedclass", "class_room_picture_find", query);
		if (res.length == 0) {
			render(fd.data.node, '', P02, 'P01');
		} else {
			const fznos = res.map((d: any) => {
				return d.fzno;
			});
			res.max_fzno = Math.max(...fznos);
			render(fd.data.node, res, P01, 'P01');
		}
	}
};
export default function main(html: HTMLElement, url: string, query: any) {
	return init('zj-reality-picture-001', s, daoke, html, url, query, { spaceid: 'flippedclass', systemid: '5991', refsystemid: '@refsystemid' });
}
